package com.ssyt.hiring.common;

import java.util.UUID;

import com.ssyt.hiring.common.util.MailUtil;
import com.ssyt.hiring.talent.service.TalentService;


public class CommonService {
	
	private TalentService talentService = new TalentService();

	/**
	 * 发送找回密码邮件
	 * 
	 * @param email
	 * @param accountType
	 * @return
	 */
	public boolean send(String email, String accountType) {
		String securityKey=UUID.randomUUID().toString();
		
		StringBuffer sb = new StringBuffer();
		sb.append("<p>你好 <a href=\"mailto:" + email + "\" target=\"_blank\">"
				+ email + "</a>!</p>");
		sb.append("<p>您已经请求了重置密码，您可以</p>");
		sb.append("<p><a href=\"http://localhost:8080/hiring/CommonServlet?command=toUpdatePasswordUI&email="
				+ email
				+ "&accountType="
				+ accountType
				+ "&securityKey="
				+ securityKey
				+ "\" target=\"_blank\">点此链接重置密码（此链接5分钟内有效）</a></p>");
		sb.append("<p>如果你没有请求重置密码，请忽略这封邮件</p>");
		sb.append("<p>在你点击上面链接修改密码之前，你的密码将会保持不变。</p>");
		boolean sendResult=MailUtil.send(email,"Hiring重置密码信息", sb.toString());
		if(sendResult){
			//如果发送成功，就更新邮件过期时间和密钥
			long millis=System.currentTimeMillis()+(5*60*1000);
			talentService.updateSecurityKeyAndEmailLinkOutDate(email,
					accountType, millis, securityKey);
			
		}
		return sendResult;
	}
}
